import Koa from 'koa';

import { contentServe } from '../../server';
const create = async (ctx: Koa.Context) => {
  try {
    const { request } = ctx;
    const res = await contentServe.create({
      ...request.body,
    });
    ctx.body = res;
  } catch (e) {
    throw {
      code: "3001",
      e
    };
  }
};
const edit = async (ctx: Koa.Context) => {
  try {
    const { request } = ctx;
    const res = await contentServe.update({
      ...request.body,
    });
    ctx.body = "修改成功";
  } catch (e) {
    throw {
      code: "3001",
      e
    };
  }
};

const details = async (ctx: Koa.Context) => {
  const { request } = ctx;
  if (!request.query.id) {
    throw {
      code: "3001",
    };
  } else {
    const res = await contentServe.findByPk(request.query.id as string);
    if (res) {
      ctx.body = res;
    } else {
      throw {
        code: "4002",
      }
    }
  }
};
export default {
  create,
  edit,
  details,
}
